<template>
  <div>
    <!-- 顶部 -->
    <top-nav></top-nav>
    <!-- form -->
    <van-form @submit="onSubmit" class="goods-form">
      <van-field
        v-model="username"
        name="goodsName"
        placeholder="请输入商品名称"
        :rules="[{ required: true, message: '请输入商品名称nnpm' }]"
      />
      <div style="margin: 16px;">
        <van-button  block type="info" native-type="submit">添加商品</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import TopNav from '../../tabbar/TopNav.vue'

export default {
  data () {
    return {
      username: ''
    }
  },

  components: {
    TopNav
  },

  methods: {
    // 提交表单  /api/addproduct
    async onSubmit (val) {
      const { data: res } = await this.$axios.post('/api/addproduct', { name: this.username })
      if (res.status !== 0) return this.$toast('添加失败')
      this.$toast.success('添加成功')
      this.$router.push('search')
    }
  }
}
</script>

<style scoped>

.left,
.right {
  width: 60px;
  color: #fff;
}

.cneter {
  flex: 1;
  margin: auto;
  color: #fff;
}

</style>
